<?php
namespace App\Repositories;

use App\Exceptions\BasicException;
use Illuminate\Support\Facades\Hash;
use function Matrix\add;    //引入hash

class LisenceOrderRepository
{
    /**
     * 资质订单列表
     * @param  $add_time
     * @param  $save_time
     * @param  $param
     * @param  $page
     * @param  $perPage
     * @return bool
     */
    public function orderList($add_time,$save_time,$param,$page=1,$perPage=20)
    {
        $list = app('model_lisence_order')
            ->with('lisence:lisence_id,lisence_name')
            ->with('user_data:user_id,user_code,nickname')
            ->whereBetween('add_time',[$add_time['start_at'],$add_time['end_at']])
            ->whereBetween('update_time',[$save_time['start_at'],$save_time['end_at']]);
        if (isset($param['order_no'])){
            $list=$list->where('order_no','like',"%{$param['order_no']}%");
        }
        if (isset($param['user_code'])){
            $user_code =$param['user_code'];
            $list=$list->whereHas('user_data',function ($query) use ($user_code){
                $query->where('user_code','like',"%{$user_code}%");
            });
        }
        if (isset($param['status'])){
            $list=$list->where('status',$param['status']);
        }
        if (isset($param['is_auto'])){
            $list=$list->where('is_auto',$param['is_auto']);
        }
        if (isset($param['is_comment'])){
            $list=$list->where('is_comment',$param['is_comment']);
        }

        if (isset($param['is_settlement'])){
            $list=$list->where('is_settlement',$param['is_settlement']);
        }
        $list=$list->orderBy('add_time','desc')->paginate($perPage, ['*'], '', $page);
        return $list;
    }

    /**
     * 获取订单详情
     * @param  $order_id
     * @return bool
     */

    public   function orderDetail($order_id){
        $detail = app('model_lisence_order')->where('order_id',$order_id)->first();
        return $detail;
    }
    /**
     * 获取订单详情
     * @param  $order_id
     * @return bool
     */
    public  function  saveStatus($order_id){
        $save = app('model_lisence_order')->where('order_id',$order_id)->update(['status'=>9]);
        return $save;
    }

}


?>